using SqlSugar;
using System.Linq.Expressions;
using System.Reflection;

namespace xjjxmm.infrastructure.repository.interfaces;

public class SqlContext : ISqlContext
{
    private readonly ISqlSugarClient _context;

    public SqlContext(ISqlSugarClient client)
    {
        this._context = client;
    }

    public string GetTableName<T>()
    {
        return typeof(T).GetCustomAttribute<SugarTable>()?.TableName ?? typeof(T).Name;
    }

    public void BeginTran()
    {
        _context.AsTenant().BeginTran();
    }

    public void CommitTran()
    {
        _context.AsTenant().CommitTran();
    }

    public void RollbackTran()
    {
        _context.AsTenant().RollbackTran();
    }
}
